cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA21.log", replace

clear all
set more off

mat TableA21 = J(15, 10, -9)

use "RawData/anes_timeseries_cdf.dta", clear
keep if VCF0004 >= 1960

foreach variable of varlist VCF080* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF081* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF082* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF083* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF084* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF085* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF086* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF087* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF088* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF089* {
display "`variable'"
tab `variable' VCF0004
}

//
// Issue Positions
//

// 2-Point Scale
foreach variable of varlist VCF0805 VCF0808 VCF0816 VCF0826 VCF0828 VCF0829 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = `variable' - 1
}

// 2-Point Scale (1 to 5)
foreach variable of varlist VCF0833 VCF0878 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 2-Point Scale (reversed)
foreach variable of varlist VCF0819 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' =  2 - `variable' 
}

// 3-Point Scale
foreach variable of varlist VCF0814 VCF0815 VCF0827 VCF0886 VCF0887 VCF0888 /*
*/ VCF0889 VCF0890 VCF0891 VCF0892 VCF0893 VCF0894 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 2
}

// 4-Point Scale
foreach variable of varlist VCF0837 VCF0838 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 3
}

// 4-Point Scale (1, 2, 4, 5)
foreach variable of varlist VCF0818 VCF0867a VCF0876a VCF0877a {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 3 | /*
*/ `variable' == 7 | `variable' == 8 | `variable' == 9 
replace `variable' = 0 if `variable' == 1
replace `variable' = 1/3 if `variable' == 2
replace `variable' = 2/3 if `variable' == 4
replace `variable' = 1 if `variable' == 5
}

// 5-Point Scale
foreach variable of varlist VCF0879 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 5-Point Scale (reversed)
foreach variable of varlist VCF0844 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (5 - `variable') / 4
}


// 7-Point Scale
foreach variable of varlist VCF0806 VCF0809 VCF0811 VCF0817 /*
*/ VCF0827a VCF0830 VCF0832 VCF0834 VCF0839 VCF0841 VCF0842 VCF0843 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 6
}

//
// Ideology
//

// 97-Point Scale
foreach variable of varlist VCF0801 {
tab `variable' VCF0004
replace `variable' = . if `variable' == 98 | `variable' == 99 
replace `variable' = (`variable' - 1) / 96
}
//
// Economic Well Being
//

// 3-Point Scale (reversed)
foreach variable of varlist VCF0880 VCF0881 {
tab `variable' VCF0004
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (3 - `variable') / 2
}


local i = 0
foreach var of varlist VCF0816 VCF0826 VCF0828 VCF0829 VCF0833 VCF0878 /*
*/ VCF0819 VCF0814 VCF0815 VCF0827 VCF0886 VCF0887 VCF0888 VCF0889 VCF0890 /*
*/ VCF0891 VCF0892 VCF0893 VCF0894 VCF0837 VCF0838 VCF0867a VCF0876a VCF0877a /*
*/ VCF0879 VCF0844 VCF0806 VCF0809 VCF0811 VCF0817 VCF0827a VCF0830 VCF0832 /*
*/ VCF0834 VCF0839 VCF0841 VCF0842 VCF0843 VCF0805 VCF0808 VCF0818 VCF0801 /*
*/ VCF0880 VCF0881 {
local i = `i' + 1
display "`i'"
tab `var'
rename `var' Issue`i'
}

keep VCF0004 VCF0009z VCF0104 VCF0110 Issue* 
gen ID = _n
reshape long Issue, i(ID VCF0004 VCF0009z VCF0104 VCF0110) j(issuenum)
drop if missing(Issue)

gen female = (VCF0104 == 2)
gen yearXissue = string(VCF0004) + string(issuenum) 

// All Issues

local column = 1

gen sample = (issuenum <= 41)

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// Social Welfare Spending:
// VCF0805: Government Assistance with Medical Care (39)
// VCF0806: Government Health Insurance Scale (27)
// VCF0808: Guaranteed Jobs and Income (40)
// VCF0809: Guaranteed Jobs and Income Scale (28)
// VCF0830: Aid to Blacks Scale (32)
// VCF0839: Government Services-Spending Scale (35)
// VCF0886: Federal Spending- Poor/Poor People (11)
// VCF0887: Federal Spending- Child Care (12)
// VCF0889: Federal Spending- Research/Fight Aids (14)
// VCF0890: Federal Spending- Public Schools (15)
// VCF0893: Federal Spending- The Homeless (18)
// VCF0894: Federal Spending- Welfare (19)

local column = 2

gen sample = 0
foreach num of numlist 39 27 40 28 32 35 11 12 14 15 18 19 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// Use of Force:
// VCF0826: Did U.S. Do  Right Thing Getting Involved in War (2)
// VCF0827: How Should  U.S. Proceed in Current War (10)
// VCF0827a: U.S. Stand in Vietnam Scale (31)
// VCF0828: Should Government Cut Military Spending (3)
// VCF0841: Cooperation with U.S.S.R. Scale (36)
// VCF0843: Defense Spending Scale (38)
// VCF0844: How Willing Should U.S. Be to Use Military Force (26)

local column = 3

gen sample = 0
foreach num of numlist 2 10 31 3 36 38 26 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// Race:
// VCF0811: Urban Unrest Scale (29)
// VCF0814: Civil Rights Pushes Too Fast or Not Fast Enough (8)
// VCF0815: Segregation or Desegregation (9)
// VCF0816: Should Government Ensure School Integration (1)
// VCF0817: School Busing Scale (30)
// VCF0818: Should Government Ensure Fair Jobs/Housing for Blacks (41)
// VCF0819: Open Housing (7)
// VCF0867a: Affirmative Action in Hiring/Promotion (22)

local column = 4

gen sample = 0
foreach num of numlist 29 8 9 1 30 41 7 22 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// VCF0834: Women Equal Role Scale (34)

local column = 5

gen sample = 0
foreach num of numlist 34 {
replace sample = 1 if issuenum == `num'
}

local i = 4
foreach num of numlist 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// Abortion
// VCF0837: When Should Abortion Be Allowed (20)
// VCF0838: By Law, When Should Abortion Be Allowed (21)

local column = 6

gen sample = 0
foreach num of numlist 20 21 {
replace sample = 1 if issuenum == `num'
}

local i = 4
foreach num of numlist 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// VCF0833: Favor or Oppose Equal Rights Amendment (5)

local column = 7

gen sample = 0
foreach num of numlist 5 {
replace sample = 1 if issuenum == `num'
}

local i = 4
foreach num of numlist 1970 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample sample2
}

// VCF0801: Index for Thermometer Rating of Liberals and Conservatives (42)

local column = 8

gen sample = 0
foreach num of numlist 42 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// VCF0880: Better or Worse Off in Past Year (43)

local column = 9

gen sample = 0
foreach num of numlist 43 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

// VCF0881: Better or Worse Off in Next Year (44)

local column = 10

gen sample = 0
foreach num of numlist 44 {
replace sample = 1 if issuenum == `num'
}

local i = 1
foreach num of numlist 1960 1970 1980 1990 {
gen sample2 = sample * (VCF0004 >= `num' & VCF0004 <= `num' + 8)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
local i = `i' + 3
drop yearXissuedum* sample2
}
gen sample2 = sample * (VCF0004 >= 2000 & VCF0004 <= 2012)
tab yearXissue if sample2 == 1, gen(yearXissuedum)
drop yearXissuedum1
regress Issue female yearXissuedum* [pweight = VCF0009z] if sample2 == 1, robust cluster(ID)
mat TableA21[`i', `column'] = _b[female]
mat TableA21[`i' + 1, `column'] = -_se[female]
mat TableA21[`i' + 2, `column'] = e(N)
drop yearXissuedum* sample sample2

matlist TableA21

log close
